<template>
  <Transition name="dialog-fade">
    <div v-if="isVisible" class="dialog-overlay" @click.self="handleClose">
      <div class="dialog-container">
        <div class="dialog-header">
          <h3 class="text-xl font-bold text-gray-800 dark:text-white">{{ title }}</h3>
          <button class="close-button" @click="handleClose" type="button" aria-label="关闭">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="dialog-content">
          <template v-if="showContact">
            <div class="contact-info bg-gray-50 dark:bg-gray-800 p-4 rounded-lg">
              <h4 class="text-lg font-semibold text-gray-800 dark:text-white mb-3">联系我们</h4>
              <div class="space-y-2">
                <a :href="'mailto:' + contact.email" class="contact-item">
                  <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
                  </svg>
                  <span>{{ contact.email }}</span>
                </a>
                <a :href="'tel:' + contact.phone" class="contact-item">
                  <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"/>
                  </svg>
                  <span>{{ contact.phone }}</span>
                </a>
                <div class="contact-item">
                  <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
                  </svg>
                  <span>{{ contact.workTime }}</span>
                </div>
              </div>
            </div>
          </template>
          <template v-else>
            <pre class="whitespace-pre-wrap text-gray-600 dark:text-gray-300 font-sans leading-relaxed mb-6">{{ message }}</pre>
          </template>
          <slot></slot>
        </div>
        <div class="dialog-footer">
          <button v-if="showCancel" class="cancel-button" @click="handleCancel">
            {{ cancelText }}
          </button>
          <button v-if="showConfirm" class="confirm-button" @click="handleConfirm">
            {{ confirmText }}
          </button>
        </div>
      </div>
    </div>
  </Transition>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'
import { pageData } from '@/composables/data/pageData'

const contact = pageData.common.contact

const props = defineProps({
  isVisible: {
    type: Boolean,
    required: true
  },
  title: {
    type: String,
    default: ''
  },
  message: {
    type: String,
    default: ''
  },
  type: {
    type: String,
    default: 'info'
  },
  showCancel: {
    type: Boolean,
    default: true
  },
  showConfirm: {
    type: Boolean,
    default: true
  },
  showContact: {
    type: Boolean,
    default: false
  },
  cancelText: {
    type: String,
    default: '取消'
  },
  confirmText: {
    type: String,
    default: '确认'
  }
})

const emit = defineEmits(['update:is-visible', 'confirm', 'cancel'])

const handleClose = () => {
  emit('update:is-visible', false)
}

const handleConfirm = () => {
  emit('confirm')
}

const handleCancel = () => {
  emit('cancel')
}
</script>

<style scoped>
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.dialog-container {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

.dark .dialog-container {
  background: #1f2937;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #e5e7eb;
}

.dark .dialog-header {
  border-color: rgba(255, 255, 255, 0.1);
}

.close-button {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.25rem;
  color: #6b7280;
  cursor: pointer;
  transition: color 0.2s;
}

.close-button:hover {
  color: #111827;
}

.dark .close-button:hover {
  color: #ffffff;
}

.dialog-content {
  margin-bottom: 1.5rem;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #e5e7eb;
}

.dark .dialog-footer {
  border-color: rgba(255, 255, 255, 0.1);
}

.cancel-button,
.confirm-button {
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  font-weight: 500;
  transition: all 0.2s;
}

.cancel-button {
  background-color: #f3f4f6;
  color: #374151;
}

.cancel-button:hover {
  background-color: #e5e7eb;
}

.dark .cancel-button {
  background-color: #374151;
  color: #e5e7eb;
}

.dark .cancel-button:hover {
  background-color: #4b5563;
}

.confirm-button {
  background-color: #2563eb;
  color: white;
}

.confirm-button:hover {
  background-color: #1d4ed8;
}

.dark .confirm-button {
  background-color: #3b82f6;
}

.dark .confirm-button:hover {
  background-color: #2563eb;
}

.contact-info {
  border: 1px solid #e5e7eb;
}

.dark .contact-info {
  border-color: rgba(255, 255, 255, 0.1);
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  color: #4b5563;
  text-decoration: none;
  transition: all 0.2s;
}

.contact-item:hover {
  background-color: rgba(0, 0, 0, 0.05);
  border-radius: 0.375rem;
}

.dark .contact-item {
  color: #e5e7eb;
}

.dark .contact-item:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

/* 动画效果 */
.dialog-fade-enter-active,
.dialog-fade-leave-active {
  transition: opacity 0.3s ease;
}

.dialog-fade-enter-from,
.dialog-fade-leave-to {
  opacity: 0;
}

.dialog-fade-enter-active .dialog-container {
  animation: dialog-zoom-in 0.3s ease-out forwards;
}

.dialog-fade-leave-active .dialog-container {
  animation: dialog-zoom-out 0.3s ease-in forwards;
}

@keyframes dialog-zoom-in {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes dialog-zoom-out {
  from {
    transform: scale(1);
    opacity: 1;
  }
  to {
    transform: scale(0.95);
    opacity: 0;
  }
}
</style>
